package com.example.daily.data.dao

import androidx.room.*
import com.example.daily.data.entity.WeightRecord
import kotlinx.coroutines.flow.Flow

@Dao
interface WeightRecordDao {
    @Insert
    suspend fun insertWeightRecord(weightRecord: WeightRecord)

    @Delete
    suspend fun deleteWeightRecord(weightRecord: WeightRecord)

    @Query("SELECT * FROM weight_records WHERE userId = :userId ORDER BY recordDate DESC")
    fun getAllWeightRecords(userId: Int): Flow<List<WeightRecord>>

    @Query("SELECT * FROM weight_records WHERE userId = :userId AND recordDate BETWEEN :startTime AND :endTime ORDER BY recordDate ASC")
    fun getWeightRecordsByDateRange(userId: Int, startTime: Long, endTime: Long): Flow<List<WeightRecord>>

    @Query("SELECT * FROM weight_records WHERE userId = :userId ORDER BY recordDate DESC LIMIT 1")
    suspend fun getLatestWeight(userId: Int): WeightRecord?

    @Query("SELECT * FROM weight_records WHERE userId = :userId ORDER BY recordDate DESC LIMIT :limit")
    fun getRecentWeightRecords(userId: Int, limit: Int): Flow<List<WeightRecord>>
} 